﻿#ifndef TRANSFERPROXY_H
#define TRANSFERPROXY_H

#include <QObject>
#include <QVector>
#include "../CommonDefine.h"
#include <QTcpSocket>

class TransferBase;

class TransferProxy : public QObject {
    Q_OBJECT
    QML_PROPERTY_(comInfo, QString, "")

public:
    using ptr = std::shared_ptr<TransferProxy>;
    TransferProxy(){}
    explicit                TransferProxy(QTcpSocket* tcpSocket);
    /**
     * @brief sendInfo
     * @param infoType
     * @param var
     * @return 没有发送对象返回false
     */
    bool                    sendInfo(const QString& infoType, const QVariant& var, const QVariant& extra = "");
    void                    recvInfo(const QString& recvInfo);
    //根据发送获取指针，如果指针不存在则会创建
    TransferBase*           getPtr(const QString& infoType);
    QTcpSocket*             getSocket(){return mTcpSocket;}
    /**
     * @brief 更新聊天信息
     * @param isSendFlag 更新的信息是发送还是接受
     * @param infoType   更新
     * @param message
     */
    void                    updataComInfo(bool isSendFlag, const QString& message);
    void                    setSendName(const QString& name){mSendName = name;}
    void                    setReceiveName(const QString& name){mReceiveName = name;}
    //是否还有接受中的任务，如果有 返回指针，如果没有返回空指针
    TransferBase*           isHaveReceiving();

public slots:
    void                    sendImage(QString path);
    void                    sendMovie(QString path);
    void                    sendTextInfo(QString info);
    void                    removeInfoDir();

protected:
    QVector<TransferBase*>  mTransVec;
    QTcpSocket*             mTcpSocket = nullptr;
    //发送者名字
    QString                 mSendName = "";\
    //接受者名字
    QString                 mReceiveName = "";
};

#endif // TRANSFERPROXY_H
